﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace IloveRSS.Models.VO
{
    public class ChannelVO
    {
        private int channelID;

        public int ChannelID
        {
            get { return channelID; }
            set { channelID = value; }
        }
        
        private String name;

        public String Name
        {
            get { return name; }
            set { name = value; }
        }

        private String description;

        public String Description
        {
            get { return description; }
            set { description = value; }
        }

        private String rate;

        public String Rate
        {
            get { return rate; }
            set { rate = value; }
        }

        private String listTags;

        public String ListTags
        {
            get { return listTags; }
            set { listTags = value; }
        }

        public ChannelVO() {}

        public ChannelVO(Channels channel, List<Tags> tags)
        {
            name = channel.ChannelName;

            foreach(Tags tag in tags)
            {
                listTags = tag + "\n";
            }
        }

        public ChannelVO(int channelID, String channelName, String description, IEnumerable<Tags> tags, int rate)
        {
            this.ChannelID = channelID;
            this.Name = (null != channelName) ? channelName.Trim() : String.Empty;
            this.Description = (null != description) ? description.Trim() : String.Empty;
            this.Rate = rate.ToString().Trim();
            this.ListTags = FormatTags(tags);
        }

        private String FormatTags(IEnumerable<Tags> tags)
        {
            List<Tags> tempList = tags.ToList<Tags>();
            String result = String.Empty;
            if(tempList.Count > 0)
            {
                result = tempList[0].Text.Trim();
                tempList.RemoveAt(0);
                foreach (Tags tag in tempList)
                {
                    result += ", " + tag.Text.Trim();
                }
            }
            return result;
        }
    }
}